package com.ald.plane_tool.viewpageradapater;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.ald.plane_tool.R;

public class MyPagerAdapter extends FragmentPagerAdapter {
    private Context context;
    private Fragment[]fragmentList;
    private String[]  list_Title;
    final int PAGE_COUNT=4;
    private String tabTitles[]=new String[]{"日本手", "美国手", "中国手"};
    public MyPagerAdapter(FragmentManager fm, Context context, Fragment[] fragmentList, String[]  list_Title) {
        super(fm);
        this.context = context;
        this.fragmentList = fragmentList;
        this.list_Title = list_Title;
    }
    //注意！！！这里就是我们自定义的布局tab_item
    public View getCustomView(int position){
        View view= LayoutInflater.from(context).inflate(R.layout.tab_itm,null);
        TextView tv= (TextView) view.findViewById(R.id.iv);
        switch (position){
            case 0:
                //drawable代码在文章最后贴出
                tv.setText("日本手");
                break;
            case 1:

                tv.setText("美国手");
                break;
            case 2:
//
                tv.setText("中国手");
                break;
        }
        return view;
    }
    @Override
    public Fragment getItem(int position) {
        return fragmentList[position];
    }

    @Override
    public int getCount() {
        return list_Title.length;
    }

    /**
     * //此方法用来显示tab上的名字
     *
     * @param position
     * @return
     */
    @Override
    public CharSequence getPageTitle(int position) {
        return list_Title[position];
    }
}